package com.xuan.juc.stream;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/*
* 5个用户！ 筛选
* 1. ID必须是偶数
* 2. 年龄必须大于23岁
* 3. 用户名转为大写字母
* 4. 用户名字母倒序
* 5. 只输出一个用户
*
* */
public class StreamTest1 {
    public static void main(String[] args) {
        User u1 = new User(1,"a",21);
        User u2 = new User(2,"b",22);
        User u3 = new User(3,"c",23);
        User u4 = new User(4,"d",24);
        User u5 = new User(5,"e",25);

        List<User> list = Arrays.asList(u1,u2,u3,u4,u5);
        list.stream().filter((u)->{return u.getId()%2==0;})
                .filter(u->{return u.getAge()>23;})
                .map(u->{return u.getName().toUpperCase();})
                .sorted((usr1,usr2)->{return usr2.compareTo(usr1);})
                .limit(1)
        .forEach(System.out::println);

        List<User> list2 = list.stream().map(m->{
            m.setAge(m.getAge()* 2);
            return m;
        }).collect(Collectors.toList());

        System.out.println(list2);

    }
}
